package edu.sias.hyzn.service.impl;

import edu.sias.hyzn.domain.Patient;
import edu.sias.hyzn.domain.Visit;
import edu.sias.hyzn.mapper.PatientMapper;
import edu.sias.hyzn.mapper.VisitMapper;
import edu.sias.hyzn.service.IVisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VisitService implements IVisitService {

    private final VisitMapper visitMapper;
    private final PatientMapper patientMapper;


    @Autowired
    public VisitService(VisitMapper visitMapper, PatientMapper patientMapper) {
        this.visitMapper = visitMapper;
        this.patientMapper = patientMapper;
    }

    @Override
    public int bindPatient(Long patientId, Long[] visitIds) {
        Patient patient = patientMapper.selectPatientById(patientId);
        if (patient == null) {
            return 0;
        }
        return visitMapper.bindPatient(patientId, visitIds);
    }

    @Override
    public int misdiagnose(Visit visit) {
        return visitMapper.updateVisit(visit);
    }

}
